package com.foreknow.domo11;

import jdk.nashorn.internal.ir.LabelNode;

public class Cat extends Animal {


//    public Cat(String name, int legNum) {
//        super(name, legNum);
//    }

    @Override
    public void shout() {
        System.out.println("喵喵......");
    }

    public Animal[] showInfo() {
        Animal[] animals = new Animal[2];

        Cat cat = new Cat();
        cat.setName("tom");
        cat.setLegNum(4);

        Duck duck = new Duck();
        duck.setName("gaga");
        duck.setLegNum(2);

        animals[0] = cat;
        animals[1] = duck;
        return animals;
    }

    public static void main(String[] args) {
        Animal animal = new Cat();
        animal.setName("abc");
        System.out.println(animal.getName());
        animal.shout();


        animal = new Duck();
        animal.setName("def");
        System.out.println(animal.getName());
        animal.shout();

        //创建一个数组容器并添加Cat和Duck对象，遍历输出


        Cat cat1 = new Cat();
        Animal[] animals = cat1.showInfo();

        for (int i = 0;i<animals.length;i++) {
            Animal a = animals[i];
            System.out.println(a.getName());
            a.shout();
        }

    }
}
